<?php
class Article_category_relation extends BaseModel
{
	public static function model($className = __CLASS__)
	{
		return parent::model($className);
	}
	
	public function tableName()
	{
	    return strtolower(get_class($this));
	}
	
	public function relations()
	{
		return array(
			'obj'=>array(self::BELONGS_TO,'Article','obj_id'),
			'cat'=>array(self::BELONGS_TO,'Article_category','category_id'),
		);
	}
	
	public function newrecord($obj_id,$category_id)
	{
		$record = $this->find("obj_id=$obj_id and category_id=$category_id");
		if($record)
		{
			return true;
		}
		$newrecord = new self();
		$newrecord->obj_id = $obj_id;
		$newrecord->category_id = $category_id;
		if($newrecord->save())
		{
			return $newrecord->id;
		}
		return false;
	}
}